package pro.cherish.smartfile.rest.tool;

import cn.hutool.core.util.ObjectUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pro.cherish.smartfile.common.response.Result;
import pro.cherish.smartfile.component.FastUploadHelper;
import pro.cherish.smartfile.component.FileManager;
import pro.cherish.smartfile.module.entity.Attachment;
import reactor.core.publisher.Mono;

/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-12-07 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：ToolController
 * @Description 功能说明：
 * <p>
 *
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-12-07 lys
 */
@RestController
@Api("工具")
@RequestMapping("/api/v1/tool")
public class ToolController {

    @Autowired
    private FileManager fileManager;

    @ApiOperation("完整清除一个任务")
    @PostMapping("delTsk")
    public Mono<Result> clearTask(@ApiParam("任务ID") String taskId) {
        Attachment archive = FastUploadHelper.getInstance().getArchiveWithDb(taskId);
        if (ObjectUtil.isNotNull(archive)) {
            fileManager.clearTaskWithFileAndRedis(archive.getUpdateTime(),taskId);
        }
        return Mono.just(Result.ok());
    }
}
